import { getPageAreaWithAttr } from '@/api/system/extendPage';
export default function () {
  return {
    provide() {
      return {
        // 这里需要调用被混入组件的表单实例reflesh 表格
        crud: this.$refs.crud
      };
    },
    data() {
      return {
        pagePath: this.$route.fullPath,
        customAttributeList: [],
        customAttributeSearch: []
      };
    },
    created() {
      console.log(this[this.options]);
      console.log(this.pagePath, this.detailOption);
      getPageAreaWithAttr({ parentAreaCode: this.pagePath }).then((res) => {
        this.customAttributeList = this._get(res, 'data.data', []);
        let searchOption = this._find(this.customAttributeList, { type: 'SEARCH' });
        let searchOptionName = searchOption && searchOption.code.includes('-') ? searchOption.code.split('-')[0] : '';
        this._forEach(this.customAttributeList, (item) => {
          this._forEach(item.pageAttributeVOList, (attrItem) => {
            if (this[item.code]) {
              this[item.code].column.push({
                label: attrItem.lableCnName,
                prop: attrItem.attributeKey,
                type: attrItem.controlType,
                disabled: attrItem.isAllowEdit,
                value: attrItem.defaultValue,
                span: attrItem.width ? Number(attrItem.width) : attrItem.pageAreaType === 'DIALOG' ? 12 : 6
              });
            }
          });
        });
        if (searchOptionName) {
          this._forEach(searchOption.pageAttributeVOList, (item) => {
            let columnIndex = this._findIndex(this[searchOptionName].column, { prop: item.attributeKey });
            this[searchOptionName].column[columnIndex]['search'] = true;
            this.customAttributeSearch.push(item.attributeKey);
          });
        }
      });
      // this[this.options].column.push({ label: '自定义属性1', prop: 'extendField1', order: 1 }, { label: '自定义属性2', prop: 'extendField2', order: 3 });
    },
    computed: {},
    methods: {}
  };
}
